#include "target.h"

Target::Target() :
    Rectangle(),
    health_(1)
{
}

Target::Target(float x, float y, float width, float height) :
    Rectangle(x, y, width, height),
    health_(1)
{
}

unsigned Target::health() const
{
    return health_;
}

void Target::decreaseHealth()
{
    if(health_ != 0) --health_;
}

void Target::resetHealth()
{
    health_ = 1;
}

bool Target::isInside(const Ball &ball) const
{
    if(health_ == 0) return false;

    const float min_x = ball.getX() - ball.getRadius();
    const float max_x = ball.getX() + ball.getRadius();
    const float min_y = ball.getY() - ball.getRadius();
    const float max_y = ball.getY() + ball.getRadius();

    if ((getX() > max_x) || ((getX() + getWidth()) < min_x))
    {
        return false;
    }
    if ((getY() > max_y) || (getY() + getHeight() < min_y))
    {
        return false;
    }

    return  true;
}
